1. Field of the Invention
The invention relates to flash memories, and more particularly to a data writing method of flash memories.
2. Description of the Related Art
A flash memory comprises a plurality of blocks, and each of the blocks comprises a plurality of pages for data storage. A flash memory writes data in a unit of a page, and erases data in a unit of a block. In other words, the flash memory can respectively write data to a plurality of pages, but data cannot be respectively erased from each of the pages. After the flash memory erases data from all pages of a block, the flash memory can then, again, write data to the pages of the block. Because a block comprises a plurality of pages, erasing data from a block requires a long period of time. A flash memory therefore cannot erase data in a high frequency; otherwise, delay is caused, which lower performance of the flash memory.
To reduce space occupied by data in a flash memory, the controller fills as much data as possible to a specific page of the flash memory when writing data. If the amount of the data is less than the capacity of the specific page, the controller stores the data in a buffer and waits for subsequent data transmitted from a host. After the buffer stores data with an amount equal to the capacity of the specific page, the controller then writes the data stored in the buffer to the specific page. However, the buffering operation causes a delay in execution of write commands sent from the host and is an extra burden on the controller.
Referring to FIG. 1, a flowchart of a conventional method 100 for writing data to a flash memory is shown. A host first transmits data to a flash storage device (step 102). The flash storage device then receives data from the host (step 104). A controller of the flash storage device then determines whether the amount of the received data is equal to a multiple of a page of a flash memory of the flash storage device (step 106). When the amount of the received data is equal to a multiple of a page, the controller directly writes the received data to a plurality of pages of the flash memory (step 118). When the amount of the received data is not equal to a multiple of a page, the controller separates the received data into a plurality of page data segments and remnant data, wherein the amount of each of the page data segments is equal to a the capacity of the page, and the amount of the remnant data is less than the capacity of the page (step 107). The controller then stores the remnant data in a buffer (step 108), and writes the page data segments to a plurality of pages of the flash memory (step 110). The flash storage device then receives subsequent data from the host and stores the subsequent data to the buffer (step 112) until the amount of data stored in the buffer equals to the capacity of a page of the flash memory (step 114). Finally, the controller writes data stored in the buffer to a page of the flash memory (step 116).
Because a host generally does not transmit write data with an amount equal to a multiple of the capacity of a page of a flash memory, when a flash storage device receives write data from the host, and the controller of the flash storage device must repeatedly buffer remnant data of the write data until the buffer stores data with an amount equal to the capacity of a page. Execution of write operations sent from the host is therefore delayed, thus negatively impacting performance of the flash storage device. A method for writing data to the flash storage device is therefore required to improve efficiency of data writing operations.